package com.wanxi.model;

import lombok.Data;

@Data
//默认创建无参数的构造方法：公有的
//@NoArgsConstructor
//默认创建全参数的构造方法，公有的
//@AllArgsConstructor
public class ResultModel {
    private String msg;
    private Integer code;
    private Integer count;
    private Object data;

    private ResultModel() {
    }

    private ResultModel(String msg, Integer code, Integer count, Object data) {
        this.msg = msg;
        this.code = code;
        this.count = count;
        this.data = data;
    }

    /**
     * 影响的条数
     *
     * @param count
     * @return
     */
    public static ResultModel getResult(int count) {
//        ResultModel resultModel = new ResultModel();
//        resultModel.setCount(count);
        return getResult(null, count, 0, "");
    }

    public static ResultModel success() {
        return getResult(null, 1, 0, "success");
    }

    public static ResultModel error() {
        return getResult(null, 0, 0, "error");
    }

    /**
     * 查询的数据：一般情况下根据id查询，或者查询所有不需要查询总条数
     *
     * @param data
     * @return
     */
    public static ResultModel getResult(Object data) {
        return getResult(data, 1, 0, "success");
    }

    /**
     * 查询所有数据，并返回总条数
     *
     * @param data
     * @param count
     * @return
     */
    public static ResultModel getResult(Object data, int count) {
//        ResultModel resultModel = new ResultModel();
//        resultModel.setData(data);
//        resultModel.setCount(count);
//        return resultModel;
        return getResult(data, count, 0, "");
    }

    private static ResultModel getResult(Object data, int count, int code, String msg) {
//        ResultModel resultModel = new ResultModel();
//        resultModel.setData(data);
//        resultModel.setCount(count);
//        resultModel.setCode(code);
//        resultModel.setMsg(msg);
//        return resultModel;
        return new ResultModel(msg, code, count, data);
    }

}
